<template>
    <Card dis-hover>
        <Row align="middle" type="flex" justify="center" style="margin-top: 10px" v-if="!isShow">
            <i-col>
                <p style="color: #19be6b">保存成功</p>
            </i-col>
        </Row>
        <Form ref="formCustom" :model="formData" :rules="ruleCustom">
            <Row align="middle">
                <i-col>
                    <FormItem label="您的单位名称：" prop="orgName"  style="margin-bottom: 7px">
                        <Input v-model="formData.orgName" placeholder="请输入您的单位名称..." maxlength="50"></Input>
                    </FormItem>
                </i-col>
            </Row>
            <Row align="middle">
                <i-col>
                    <FormItem label="您的职务：" prop="position" style="margin-bottom: 7px">
                        <Select v-model="formData.position">
                            <Option v-for="item in postList" :value="item.id" :key="item.id">{{ item.name }}</Option>
                        </Select>
                    </FormItem>
                </i-col>
            </Row>
            <Row align="middle" >
                <i-col>
                    <FormItem label="您的姓名：" prop="userName" style="margin-bottom: 7px">
                        <Input v-model="formData.userName" placeholder="请输入您的姓名..." maxlength="10"></Input>
                    </FormItem>
                </i-col>
            </Row>
            <Row align="middle" >
                <i-col>
                    <FormItem label="单位现任安全总监姓名：" prop="safetyDirectorName" style="margin-bottom: 7px">
                        <Input v-model="formData.safetyDirectorName" placeholder="请输入单位现任安全总监姓名..." maxlength="10"></Input>
                    </FormItem>
                </i-col>
            </Row>
            <Row align="middle" >
                <i-col>
                    <FormItem label="单位现任安全总监职务：" prop="safetyDirectorPosition" style="margin-bottom: 7px">
                        <Select v-model="formData.safetyDirectorPosition">
                            <Option v-for="item in directorPostList" :value="item.id" :key="item.id">{{ item.name }}</Option>
                        </Select>
                    </FormItem>
                </i-col>
            </Row>
            <Row align="middle" >
                <i-col>
                    <FormItem label="现任安全总监任职资格：" prop="safetyDirectorQualification" style="margin-bottom: 7px">
                        <Select v-model="formData.safetyDirectorQualification">
                            <Option v-for="item in qualificationsList" :value="item.id" :key="item.id">{{ item.name }}</Option>
                        </Select>
                    </FormItem>
                </i-col>
            </Row>
            <Row align="middle" >
                <i-col>
                    <FormItem label="安全总监履职情况：" prop="safetyDirectorPerform" style="margin-bottom: 7px">
                        <Select v-model="formData.safetyDirectorPerform">
                            <Option v-for="item in evaluateList" :value="item.id" :key="item.id">{{ item.name }}</Option>
                        </Select>
                    </FormItem>
                </i-col>
            </Row>
            <Row align="middle">
                <i-col>
                    <FormItem label="是否延续任命现任安全总监：" prop="currentDirectorAppointed" style="margin-bottom: 7px">
                        <Select v-model="formData.currentDirectorAppointed" @on-change="changeVualue">
                            <Option v-for="item in whetherList" :value="item.id" :key="item.id">{{ item.name }}</Option>
                        </Select>
                    </FormItem>
                </i-col>
            </Row>
            <div v-if="formData.safetyDirectorPosition == '安全管理部门负责人'">
                <Row align="middle" v-if="formData.currentDirectorAppointed == '是'">
                    <i-col>
                        <FormItem label="是否可以将现任安全总监提为单位经理助理：" prop="promotionAssistantManager" style="margin-bottom: 7px">
                            <Select v-model="formData.promotionAssistantManager">
                                <Option v-for="item in whetherList" :value="item.id" :key="item.id">{{ item.name }}</Option>
                            </Select>
                        </FormItem>
                    </i-col>
                </Row>
                <Row align="middle" v-if="formData.currentDirectorAppointed == '是'&&formData.promotionAssistantManager == '否'">
                    <i-col>
                        <FormItem label="是否可以让现任安全总监享受经理助理薪资待遇：" prop="enjoyPromotionAssistantSalary" style="margin-bottom: 7px">
                            <Select v-model="formData.enjoyPromotionAssistantSalary">
                                <Option v-for="item in whetherList" :value="item.id" :key="item.id">{{ item.name }}</Option>
                            </Select>
                        </FormItem>
                    </i-col>
                </Row>
                <Row align="middle" v-if="formData.currentDirectorAppointed == '否'">
                    <i-col>
                        <FormItem label="拟推荐人员是否可以提为经理助理：" prop="candidatePromotionAssistant" style="margin-bottom: 7px">
                            <Select v-model="formData.candidatePromotionAssistant">
                                <Option v-for="item in whetherList" :value="item.id" :key="item.id">{{ item.name }}</Option>
                            </Select>
                        </FormItem>
                    </i-col>
                </Row>
                <Row align="middle" v-if="formData.candidatePromotionAssistant == '否'">
                    <i-col>
                        <FormItem label="拟推荐人员是否可以给予经理助理薪资待遇：" prop="enjoyCandidatePromotionAssistantSalary" >
                            <Select v-model="formData.enjoyCandidatePromotionAssistantSalary">
                                <Option v-for="item in whetherList2" :value="item.id" :key="item.id">{{ item.name }}</Option>
                            </Select>
                        </FormItem>
                    </i-col>
                </Row>
            </div>
        </Form>
        <Row align="middle" type="flex" justify="center" style="margin-top: 10px;" v-if="isShow">
            <i-col>
                <Button type="success" long @click="saveInfo" :loading="loading" >提交</Button>
            </i-col>
        </Row>
    </Card>
</template>

<script>
    import {Api} from '../../../api'

    export default {
        name: "questionnaire",
        data(){
            return{
                isShow: true,
                loading: false,
                formData: {},
                ruleCustom: {
                    orgName: [
                        {
                            required: true,
                            message: '  ',
                            trigger: 'blur,change'
                        }
                    ],
                    position: [
                        {
                            required: true,
                            message: '  ',
                            trigger: 'blur,change'
                        }
                    ],
                    userName: [
                        {
                            required: true,
                            message: '  ',
                            trigger: 'blur,change'
                        }
                    ],
                    safetyDirectorName: [
                        {
                            required: true,
                            message: '  ',
                            trigger: 'blur,change'
                        }
                    ],
                    safetyDirectorPosition: [
                        {
                            required: true,
                            message: '  ',
                            trigger: 'blur,change'
                        }
                    ],
                    safetyDirectorQualification: [
                        {
                            required: true,
                            message: '  ',
                            trigger: 'blur,change'
                        }
                    ],
                    safetyDirectorPerform: [
                        {
                            required: true,
                            message: '  ',
                            trigger: 'blur,change'
                        }
                    ],
                    currentDirectorAppointed: [
                        {
                            required: true,
                            message: '  ',
                            trigger: 'blur,change'
                        }
                    ],
                    promotionAssistantManager: [
                        {
                            required: true,
                            message: '  ',
                            trigger: 'blur,change'
                        }
                    ],
                    enjoyPromotionAssistantSalary: [
                        {
                            required: true,
                            message: '  ',
                            trigger: 'blur,change'
                        }
                    ],
                    candidatePromotionAssistant: [
                        {
                            required: true,
                            message: '  ',
                            trigger: 'blur,change'
                        }
                    ],
                    enjoyCandidatePromotionAssistantSalary: [
                        {
                            required: true,
                            message: '  ',
                            trigger: 'blur,change'
                        }
                    ],
                },
                postList: [
                    {
                        id: '书记',
                        name: '书记'
                    },
                    {
                        id: '经理',
                        name: '经理'
                    },
                ],
                evaluateList: [
                    {
                        id: '优秀',
                        name: '优秀'
                    },
                    {
                        id: '良好',
                        name: '良好'
                    },
                    {
                        id: '一般',
                        name: '一般'
                    },
                    {
                        id: '较差',
                        name: '较差'
                    },
                ],
                qualificationsList: [
                    {
                        id: '工程师',
                        name: '工程师'
                    },
                    {
                        id: '注安师',
                        name: '注安师'
                    },
                    {
                        id: '无',
                        name: '无'
                    },
                ],
                directorPostList: [
                    {
                        id: '企业副总',
                        name: '企业副总'
                    },
                    {
                        id: '经理助理',
                        name: '经理助理'
                    },
                    {
                        id: '安全管理部门负责人',
                        name: '安全管理部门负责人'
                    },
                ],
                whetherList: [
                    {
                        id: '是',
                        name: '是'
                    },
                    {
                        id: '否',
                        name: '否'
                    }
                ],
                whetherList2: [
                    {
                        id: '是',
                        name: '是'
                    }
                ]
            }
        },
        methods: {
            saveInfo(){
                this.$refs['formCustom'].validate((valid) => {
                    if(valid) {
                        this.loading = true;
                        this.$http.post(Api.questionnaire, this.formData).then(function(response){
                            if(response.data.status == 200){
                                this.$Message.success({ content: '保存成功', duration: 8 });
                                this.loading = false;
                                this.isShow = false;
                            }else{
                                this.$Message.error({ content: '保存失败', duration: 8 });
                            }
                        }, function(res){
                            this.$Message.error({content: '保存失败', duration: 4 });
                            this.loading = false;
                        });
                    }
                });
            },
            changeVualue(value){

                this.$delete(this.formData,'promotionAssistantManager');
                this.$delete(this.formData,'enjoyPromotionAssistantSalary');
                this.$delete(this.formData,'candidatePromotionAssistant');
                this.$delete(this.formData,'enjoyCandidatePromotionAssistantSalary');

            }
        }
    }
</script>

<style scoped>

</style>
